const {
  User
} = require('../../model/user');

const userDelete = async (req, res) => {
  // 获取要删除的用户id
  // res.send(req.body.id)

  if (req.body.id) {
    // 根据id删除用户
    const del_item = await User.findOneAndDelete({
      _id: req.body.id
    })
    if (del_item == null) {
      // del_item == null，该用户信息查询不到
      res.send({
        code: 400,
        data: {},
        msg: "该信息已删除"
      })
    } else {
      // 成功
      res.send({
        code: 200,
        data: {},
        msg: "删除成功"
      })
    }
  } else {
    // 没有id参数
    res.send({
      code: 400,
      data: {},
      msg: "缺少参数"
    })
  }
}

module.exports = userDelete;